const http = require('http')
const url = require('url')
const fs = require("fs");
const path = require("path");

// var reqUrl = "http://localhost:8081/"

// var options = url.parse(reqUrl)
// options.method = "POST"

// var reqObj = http.request(options,(res) => {

// })

var userName = process.argv[2]
var pwd = process.argv[3]
var x=0,y=0
// var userInfor = {userName:userName,pwd:pwd}
// var userStr = JSON.stringify(userInfor)
// reqObj.write(userStr)//向请求体写入数据
// reqObj.end()
var filePath = path.join(__dirname,"/data.json");

fs.readFile(filePath,(err,data) => {
    var obj = JSON.parse(data)
    // console.log(obj.userList[0].userName)
    for(var i in obj.userList) {
        if(userName === obj.userList[i].userName) {
            if(pwd === obj.userList[i].pwd) {
                console.log("登陆成功")
                x=x+1
            }
            else if(x===0){
                console.log("用户名、密码不正确")
            }
        }
        else{
            y=y+1
        }
    }
    if(y!==0){
        console.log("用户名、密码不正确")
    }

//    if (err) {
//        console.log(err);
//    } else {
//         var obj = JSON.parse(data)
    //    console.log(data.toString("utf-8"));
    //    console.log(obj.userList[1].userName)
//    }
})
